{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "通过编写Python代码说明概念分层的使用方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.axes._subplots.AxesSubplot at 0x11e42d650>"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXUAAAECCAYAAAAB2kexAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+j8jraAAAPaElEQVR4nO3de7BdZX3G8e9DAl6QGi7Hy3ghFC8UdQZnYrVoIlAFNYK1aqeWUQu1kdoZ7IyDYkU7VUczju2ILdZJxSp2/MOKFywZqyCGAAHn0FpHa7moUGgtHiKIMUWD/vrHWkf2SU5yDsk+We7X72dmz17rXWvv/cvKOs9597suJ1WFJKkNBwxdgCRpfAx1SWqIoS5JDTHUJakhhrokNWT5kB9+xBFH1MqVK4csQZImzvXXX39nVU3Nt2zQUF+5ciXT09NDliBJEyfJrbtb5vCLJDXEUJekhhjqktQQQ12SGmKoS1JDDHVJaoihLkkNMdQlqSGGuiQ1ZNArSpfCynMvHbqERbll/dqhS5DUIHvqktQQQ12SGmKoS1JDDHVJaoihLkkNMdQlqSGGuiQ1xFCXpIYY6pLUEENdkhpiqEtSQwx1SWqIoS5JDTHUJakhhrokNcRQl6SGGOqS1BBDXZIaYqhLUkMMdUlqiKEuSQ0x1CWpIYa6JDXEUJekhhjqktQQQ12SGmKoS1JDFhXqSR6a5DtJjklyWJJLklyR5JNJDu7XOTnJliRXJ3nd0pYtSZrPYnvq7wRW9NNvBj5fVScCXwPWJVkOnA+8GDgBOCvJI8ZcqyRpAQuGepJnAIcBX++b1gAb++mNw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XVxbMNSX4X2DJcSRNt9O6W7+ufAzx9gFomnfvm+LyS7hqUI4A7R54Bnp/kVVX1kt29+JeZoT4iyWHAu4DTk9xOdxe8AMfQXcGnB6aq6pvzLUiyfX8XM8ncN8fuB/1ximv65y1V9Yu/mZDkg0MWty8M9bneAZxXVT9McltVnQa/OA94Q5JTq+pnw5Y4UQKQ5Nl0gVQj7ccOVdSEct8cr8P6OzGOPs+e538jMJEXHoGhvrOzq+rn/fQHZhur6uYkfwc8nO7CBC3OFoCqupqdepNJHDJ4YNw3x6iqjpmvPcnBwFpgYu+l43nqktQQT2mUpIYY6pLUEENdkhpiqEtSQ/4fyd26DrsJRIEAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "import warnings\n",
    "import matplotlib\n",
    "import matplotlib.pyplot as plt\n",
    "# 以下 font.family 设置仅适用于 Mac系统，其它系统请使用对应字体名称\n",
    "matplotlib.rcParams['font.family'] = 'Arial Unicode MS'\n",
    "%matplotlib inline\n",
    "warnings.filterwarnings('ignore')\n",
    "boys = pd.read_csv(\"http://image.cador.cn/data/boys.csv\")\n",
    "#这里根据BMI指数，将bmi属性泛化成体重类型字段wtype\n",
    "parts = np.array([0, 18.5, 25, 28, 100])\n",
    "types = [\"过轻\",\"正常\",\"过重\",\"肥胖\"]\n",
    "boys['wtype'] = [types[np.where(x <= parts)[0][0]-1] if not np.isnan(x) else \"未知\" for x in boys.bmi]\n",
    "boys[boys.wtype!=\"未知\"].wtype.value_counts().plot.bar()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
